﻿namespace 扩展方法
{
    internal class Program
    {
        static void Main(string[] args)
        {

            WebBuilder builder = new WebBuilder();
            builder.CreateDefault()
                .AddServices()
                .AddControllers()
                .Inject((w) =>
            {
                w.AddControllers()
                .AddServices()
                .AddControllers();
            });

            Console.WriteLine("Hello, World!");
        }
    }



    internal class WebBuilder
    {




    }



    internal static class Builder
    {

        public static WebBuilder AddServices(this WebBuilder webBuilder) 
        {
            Console.WriteLine("添加一个服务");
            return webBuilder;
        }

        public static WebBuilder AddControllers(this WebBuilder webBuilder)
        {

            Console.WriteLine("添加一个控制器");

            return webBuilder;
        }

        /// <summary>
        /// Action 是一个委托
        /// </summary>
        /// <param name="webBuilder"></param>
        /// <param name="func"></param>
        /// <returns></returns>
        public static WebBuilder Inject(this WebBuilder webBuilder,Action<WebBuilder> func)
        {

            Console.WriteLine("进行依赖注入的设置");

            func(webBuilder);

            return webBuilder; 
        }


        public static WebBuilder CreateDefault(this WebBuilder webBuilder)
        {
            return webBuilder;
        }

    }
}
